package com.jrtc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jrtc.base.entity.bo.Foodrecord;
import com.jrtc.dao.FoodrecordDao;
import com.jrtc.service.FoodrecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 患者饮食记录表(Foodrecord)表服务实现类
 *
 * @author makejava
 * @since 2022-03-21 17:34:12
 */
@Service("foodrecordService")
public class FoodrecordServiceImpl implements FoodrecordService
{
    @Resource
    private FoodrecordDao foodrecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param foodrecordId 主键
     * @return 实例对象
     */
    @Override
    public Foodrecord queryById(Integer foodrecordId) {
        return this.foodrecordDao.queryById(foodrecordId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Foodrecord> queryAllByLimit(int offset, int limit) {
        return this.foodrecordDao.queryAllByLimit(offset, limit);
    }

    @Override
    public IPage<Foodrecord> queryFoodrecordList(Foodrecord foodrecord)
    {
        com.baomidou.mybatisplus.extension.plugins.pagination.Page<Foodrecord> page = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(foodrecord.getPageNo(), foodrecord.getPageSize());
        IPage<Foodrecord> foodrecordPage = this.foodrecordDao.queryFoodrecordList(page, foodrecord);
        return foodrecordPage;
    }
    /**
     * 新增数据
     *
     * @param foodrecord 实例对象
     * @return 实例对象
     */
    @Override
    public Foodrecord insert(Foodrecord foodrecord) {
        this.foodrecordDao.insert(foodrecord);
        return foodrecord;
    }

    /**
     * 修改数据
     *
     * @param foodrecord 实例对象
     * @return 实例对象
     */
    @Override
    public Foodrecord update(Foodrecord foodrecord) {
        this.foodrecordDao.update(foodrecord);
        return this.queryById(foodrecord.getFoodrecordId());
    }

    /**
     * 通过主键删除数据
     *
     * @param foodrecordId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer foodrecordId) {
        return this.foodrecordDao.deleteById(foodrecordId) > 0;
    }
}